/***************************************************************
 * Name:      proGSOF.h
 * Purpose:   Defines Application Frame
 * Author:    walnutcy (walnutcy@gmail.com)
 * Created:   2012-09-14
 * Copyright: walnutcy (weibo.com/walnutcy)
 * License:
 **************************************************************/
#ifndef PROGSOF_H
#define PROGSOF_H

#include "stdef.h"

#define GSOF_PACKET_MAX  (256+4)

#define GSOF_DATA_MAX    (256*4*10)
enum _gsof_state_
{
    GSOF_HEAD = 0,
    GSOF_A_LEN,
    GSOF_PACKET,
    GSOF_CHECK,
    GSOF_ETX,

    GSOF_MAX
};

typedef struct _GSOF_MSG_
{
    u8  state;  // decoder state machine
    u8  status; // gsof status
    u8  rlen;
    u8  plen;
    u8  check;
    u8  mDat[GSOF_PACKET_MAX];

    // PAGE COLLECT
    u16 alen;
    u8  aDat[GSOF_DATA_MAX];
} GSOF_MSG;





class proGSOF
{
public:
    proGSOF();
    virtual ~proGSOF();


    void  deinit(void);
    u8    protocol(u8 ch);
    void  decPacket(void* pParam);

protected:
private:
    GSOF_MSG  msg;
    GSOF_MSG* pMsg;

    f4  libBIN2F4(u8* pDat);
    f8  libBIN2F8(u8* pDat);

    void packGSOF_01(void* pParam, u8* p);
    void packGSOF_02(void* pParam, u8* p);
    void packGSOF_08(void* pParam, u8* p);
    void packGSOF_09(void* pParam, u8* p);
    void packGSOF_14(void* pParam, u8* p);
    void packGSOF_27(void* pParam, u8* p);
    void packGSOF_34(void* pParam, u8* p);
};

#endif // PROGSOF_H
